package com.module.sysconfig.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.module.sysconfig.entity.Zhysb;
import com.module.sysconfig.service.ZhysbService;
import com.support.helper.AjaxHelper;
import com.support.util.StringUtils;
import com.support.web.ControllerSupport;
/**
 *系统组合预设
 */
@Controller
@Scope(value = "prototype")
@RequestMapping("/sysconfig/zhysb")
public class ZhysbController extends ControllerSupport
{

	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private ZhysbService zhysbService;
	

	/**
	 * 保存系统组合预设表数据
	 * @throws IOException
	 */
	@RequestMapping("/saveZhysb")
	public void saveZhysb() throws IOException 
	{

		try 
		{
			Map<String, String> paramsMap = this.getParamsMap();
			Zhysb zhysb = new Zhysb();
			
			String FQLLXID = paramsMap.get("FQLLXID");
			String FQLLXMC = paramsMap.get("FQLLXMC");
			String FDJLXID = paramsMap.get("FDJLXID");
			String FDJLXMC = paramsMap.get("FDJLXMC");
			String ZQLLXID = paramsMap.get("ZQLLXID");
			String ZQLLXMC = paramsMap.get("ZQLLXMC");
			String ZDJLXID = paramsMap.get("ZDJLXID");
			String ZDJLXMC = paramsMap.get("ZDJLXMC");
			String BZ1 = paramsMap.get("BZ1");
			String BZ2 = paramsMap.get("BZ2");
			String BZ3 = paramsMap.get("BZ3");
			String BZ4 = paramsMap.get("BZ4");
			
			zhysb.setFqllxid(FQLLXID == null ? "":FQLLXID);
			zhysb.setFqllxmc(FQLLXMC == null ? "":FQLLXMC);
			zhysb.setFdjlxid(FDJLXID == null ? "":FDJLXID);
			zhysb.setFdjlxmc(FDJLXMC == null ? "":FDJLXMC);
			zhysb.setZqllxid(ZQLLXID == null ? "":ZQLLXID);
			zhysb.setZqllxmc(ZQLLXMC == null ? "":ZQLLXMC);
			zhysb.setZdjlxid(ZDJLXID == null ? "":ZDJLXID);
			zhysb.setZdjlxmc(ZDJLXMC == null ? "":ZDJLXMC);
			zhysb.setBz1(BZ1 == null ? "":BZ1);
			zhysb.setBz2(BZ2 == null ? "":BZ2);
			zhysb.setBz3(BZ3 == null ? "":BZ3);
			zhysb.setBz4(BZ4 == null ? "":BZ4);

			zhysbService.saveZhysb(zhysb);

			returnJSONView(AjaxHelper.toJSON(zhysb, AjaxHelper.SUCCESS,
					"组合预设数据保存！"));

		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("ZhysbController.saveZhysb:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE,
					e.getMessage()));
		}
	}

	/**
	 * 更新系统组合预设表数据 
	 * @throws IOException
	 */
	@RequestMapping("/updateZhysb")
	public void updateZhysb() throws IOException 
	{

		try 
		{
			Map<String, String> paramsMap = this.getParamsMap();
			String id = paramsMap.get("ID");
			if(StringUtils.isEmpty(id))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE,
						"缺少主键ID"));
				return;
			}
			
			Zhysb zhysb = zhysbService.queryZhysbById(Long.parseLong(id));
			
			String FQLLXID = paramsMap.get("FQLLXID");
			String FQLLXMC = paramsMap.get("FQLLXMC");
			String FDJLXID = paramsMap.get("FDJLXID");
			String FDJLXMC = paramsMap.get("FDJLXMC");
			String ZQLLXID = paramsMap.get("ZQLLXID");
			String ZQLLXMC = paramsMap.get("ZQLLXMC");
			String ZDJLXID = paramsMap.get("ZDJLXID");
			String ZDJLXMC = paramsMap.get("ZDJLXMC");
			String BZ1 = paramsMap.get("BZ1");
			String BZ2 = paramsMap.get("BZ2");
			String BZ3 = paramsMap.get("BZ3");
			String BZ4 = paramsMap.get("BZ4");
			
			zhysb.setFqllxid(FQLLXID == null ? zhysb.getFqllxid():FQLLXID);
			zhysb.setFqllxmc(FQLLXMC == null ? zhysb.getFqllxmc():FQLLXMC);
			zhysb.setFdjlxid(FDJLXID == null ? zhysb.getFdjlxid():FDJLXID);
			zhysb.setFdjlxmc(FDJLXMC == null ? zhysb.getFdjlxmc():FDJLXMC);
			zhysb.setZqllxid(ZQLLXID == null ? zhysb.getZqllxid():ZQLLXID);
			zhysb.setZqllxmc(ZQLLXMC == null ? zhysb.getZqllxmc():ZQLLXMC);
			zhysb.setZdjlxid(ZDJLXID == null ? zhysb.getZdjlxid():ZDJLXID);
			zhysb.setZdjlxmc(ZDJLXMC == null ? zhysb.getZdjlxmc():ZDJLXMC);
			zhysb.setBz1(BZ1 == null ? zhysb.getBz1():BZ1);
			zhysb.setBz2(BZ2 == null ? zhysb.getBz2():BZ2);
			zhysb.setBz3(BZ3 == null ? zhysb.getBz3():BZ3);
			zhysb.setBz4(BZ4 == null ? zhysb.getBz4():BZ4);

			zhysbService.updateZhysb(zhysb);

			returnJSONView(AjaxHelper.toJSON(zhysb, AjaxHelper.SUCCESS,
					"组合预设数据更新！"));

		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("ZhysbController.updateZhysb:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE,
					e.getMessage()));
		}
	}

	/**
	 * 删除系统组合预设数据
	 * @throws IOException
	 */
	@RequestMapping("/deleteZhysb")
	public void deleteZhysb() throws IOException 
	{
		try 
		{
			Map<String, String> paramsMap = this.getParamsMap();
			String id = paramsMap.get("ID");
			if(StringUtils.isEmpty(id))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE,
						"缺少主键ID"));
				return;
			}
			zhysbService.deleteZhysb(Long.parseLong(id));
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS,
					"删除组合预设数据！"));

		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("ZhysbController.deleteZhysb:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE,
					e.getMessage()));
		}
	}
	
	/**
	 * 查询系统组合预设所有数据
	 * @throws IOException
	 */
	@RequestMapping("/queryZhysbRecord")
	public void queryZhysbRecord() throws IOException 
	{
		try 
		{

			List<Map<String, Object>> zhysbList = zhysbService
					.queryZhysbRecord();
			returnJSONView(AjaxHelper.toJSON(zhysbList, AjaxHelper.SUCCESS,
					"组合预设数据查询！"));

		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("ZhysbController.queryZhysbRecord:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE,
					e.getMessage()));
		}
	}

}
